<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <canvas id="canvas" width="400" height="400"></canvas>
    <script src="utils.js"></script>
    <script src="arrow.js"></script>
    <script>
        var canvas = document.getElementById('canvas'),
            context = canvas.getContext('2d'),
            mouse = utils.captureTouch(canvas),
            // mouse = utils.captureMouse(canvas),
            arrow = new Arrow()

        arrow.x = canvas.width / 2
        arrow.y = canvas.height / 2

        function drawFrame() {
            window.requestAnimationFrame(drawFrame, canvas)
            context.clearRect(0, 0, canvas.width, canvas.height)

            var dx = mouse.x - arrow.x,
                dy = mouse.y - arrow.y

            arrow.rotation = 
                Math.atan2(dy, dx)
                // Math.atan(dy/dx)

            arrow.draw(context)
        }

        drawFrame()

    </script>
</body>

</html>